﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iLangl.Customer.Actions;
using iLangl.Customer.DAL;
using iLangl.Model;

namespace iLangl.Customer.DNN
{
	public class SettingsManager
	{
		#region Singelton Pattern


		private static SettingsManager instance;
		private static object mutex = new object();
		/// <summary>
		/// The instance of the SettingsManager.
		/// </summary>
		public static SettingsManager Instance
		{
			get
			{
				if (instance == null)
				{
					lock (mutex)
					{
						if (instance == null)
						{
							instance = new SettingsManager();

						}
					}
				}
				return instance;
			}
		}
		#endregion

		public IList<WorkArea> GetWorkAreas()
		{
			return DALFacade.Instance.SettingsDAL.ReadWorkAreas();
		}

		public IList<Product> GetProducts()
		{
			return DALFacade.Instance.SettingsDAL.ReadProducts();
		}

		public void DownloadiLanglSettings()
		{
			GetCustomerSettings action = new GetCustomerSettings();
			action.Execute();

			foreach(Product product in  action.Settings.Products)
			{
				DALFacade.Instance.SettingsDAL.AddProduct(product, null);
			}

			foreach (WorkArea workArea in action.Settings.WorkAreas)
			{
				DALFacade.Instance.SettingsDAL.AddWorkArea(workArea, null);
			}
		}
	}
}